package com.yuexun.beilunpatient.ui.contractmanage.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.yuexun.beilunpatient.R;
import com.yuexun.beilunpatient.base.BaseEntity;
import com.yuexun.beilunpatient.base.BaseKJActivity;
import com.yuexun.beilunpatient.config.AppConfig;
import com.yuexun.beilunpatient.ui.contractmanage.bean.RecordSummaryBean;
import com.yuexun.beilunpatient.ui.contractmanage.bean.RecordSummaryData;
import com.yuexun.beilunpatient.ui.contractmanage.model.impl.ContractManageModel;
import com.yuexun.beilunpatient.ui.contractmanage.presenter.impl.RecordSummaryPresenter;
import com.yuexun.beilunpatient.ui.contractmanage.ui.view.IRecordSummaryView;
import com.yuexun.beilunpatient.widget.EmptyLayout;

import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chenss on 2019/5/16.
 */
public class Act_Record_Summary extends BaseKJActivity implements IRecordSummaryView {

    @Bind(R.id.tv_admission_diagnosis)
    TextView tvAdmissionDiagnosis;
    @Bind(R.id.tv_dmission_status)
    TextView tvDmissionStatus;
    @Bind(R.id.tv_aiagnosis_process)
    TextView tvAiagnosisProcess;
    @Bind(R.id.tv_treatment_outcome)
    TextView tvTreatmentOutcome;
    @Bind(R.id.tv_discharge_diagnosis)
    TextView tvDischargeDiagnosis;
    @Bind(R.id.tv_discharge_status)
    TextView tvDischargeStatus;
    @Bind(R.id.tv_discharge_order)
    TextView tvDischargeOrder;
    @Bind(R.id.empty_layout)
    EmptyLayout emptyLayout;

    String HOSP_ID;
    String INP_NO;
    String personId;

    RecordSummaryPresenter presenter;

    @Override
    public void setRootView() {
        super.setRootView();
        setContentView(R.layout.act_record_summary);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        HOSP_ID = getIntent().getExtras().getString("HOSP_ID");
        INP_NO = getIntent().getExtras().getString("INP_NO");
        personId = getIntent().getExtras().getString("personId");

        presenter = new RecordSummaryPresenter(this, new ContractManageModel());
        ApiForGetList();

        emptyLayout.setOnLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                emptyLayout.setErrorType(EmptyLayout.NETWORK_LOADING);
                ApiForGetList();
            }
        });
    }


    private void ApiForGetList() {
        Map<String, String> params = new HashMap<>();
        params.put("sessionUuidPatient", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
        params.put("personId", personId);
        params.put("hospCode", HOSP_ID);
        params.put("inpNo", INP_NO);
//        params.put("sessionUuid", "9cda8d222d2e4177ab6c487bb8c1bbed");
//        params.put("personId", "330206192604113423");
//        params.put("hospCode", "41955956");
//        params.put("inpNo", "2181029");
        presenter.summaryOfDischarge(params);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.title_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.title_back:
                finish();
                break;
        }
    }

    @Override
    public void summaryOfDischarge(BaseEntity<RecordSummaryBean> list) {
        emptyLayout.setErrorType(EmptyLayout.NODATA);
        if(list.getStatus().equals("200")){
            if(list.getDatas().size() > 0){
                if (list.getDatas().get(0).getCode() == 1) {
                    RecordSummaryData summaryData = list.getDatas().get(0).getDiagnosisrow();
                    tvAdmissionDiagnosis.setText(summaryData.getInhosdiagname());
                    tvDmissionStatus.setText(summaryData.getChiefcomplatnts());
                    tvAiagnosisProcess.setText(summaryData.getTreatmentrecord());
                    tvTreatmentOutcome.setText(summaryData.getOuthresultu());
                    tvDischargeDiagnosis.setText(summaryData.getOuthdiagname());
                    tvDischargeStatus.setText(summaryData.getOuthoscondition());
                    tvDischargeOrder.setText(summaryData.getOuthorder());

                    emptyLayout.dismiss();
                }
            }
        }
    }
}
